package com.ruoyi.hyg.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hyg.domain.DailyCheckIn;
import com.ruoyi.hyg.service.IDailyCheckInService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 每日打卡Controller
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/hyg/in")
public class DailyCheckInController extends BaseController
{
    @Autowired
    private IDailyCheckInService dailyCheckInService;

    /**
     * 查询每日打卡列表
     */
    @PreAuthorize("@ss.hasPermi('hyg:in:list')")
    @GetMapping("/list")
    public TableDataInfo list(DailyCheckIn dailyCheckIn) {
        startPage();
        List<DailyCheckIn> list = dailyCheckInService.selectDailyCheckInList(dailyCheckIn);
        return getDataTable(list);
    }

    /**
     * 导出每日打卡列表
     */
    @PreAuthorize("@ss.hasPermi('hyg:in:export')")
    @Log(title = "每日打卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DailyCheckIn dailyCheckIn)
    {
        List<DailyCheckIn> list = dailyCheckInService.selectDailyCheckInList(dailyCheckIn);
        ExcelUtil<DailyCheckIn> util = new ExcelUtil<DailyCheckIn>(DailyCheckIn.class);
        util.exportExcel(response, list, "每日打卡数据");
    }

    /**
     * 获取每日打卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('hyg:in:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dailyCheckInService.selectDailyCheckInById(id));
    }

    /**
     * 新增每日打卡
     */
    @PreAuthorize("@ss.hasPermi('hyg:in:add')")
    @Log(title = "每日打卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DailyCheckIn dailyCheckIn)
    {
        dailyCheckInService.insertDailyCheckIn(dailyCheckIn);
        // 返回完整数据
        DailyCheckIn result = dailyCheckInService.selectDailyCheckInById(dailyCheckIn.getId());
        return success(result);
    }

    /**
     * 修改每日打卡
     */
    @PreAuthorize("@ss.hasPermi('hyg:in:edit')")
    @Log(title = "每日打卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DailyCheckIn dailyCheckIn)
    {
        return toAjax(dailyCheckInService.updateDailyCheckIn(dailyCheckIn));
    }

    /**
     * 删除每日打卡
     */
    @PreAuthorize("@ss.hasPermi('hyg:in:remove')")
    @Log(title = "每日打卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dailyCheckInService.deleteDailyCheckInByIds(ids));
    }
}
